{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Form Smallest Number From Two Digit Arrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #enumeration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #枚举"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: minNumber"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #从两个数字数组里生成最小数字"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "给你两个只包含 1 到 9 之间数字的数组&nbsp;<code>nums1</code> 和&nbsp;<code>nums2</code>&nbsp;，每个数组中的元素 <strong>互不相同</strong>&nbsp;，请你返回 <strong>最小</strong> 的数字，两个数组都 <strong>至少</strong> 包含这个数字的某个数位。\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums1 = [4,1,3], nums2 = [5,7]\n",
    "<b>输出：</b>15\n",
    "<b>解释：</b>数字 15 的数位 1 在 nums1 中出现，数位 5 在 nums2 中出现。15 是我们能得到的最小数字。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums1 = [3,5,2,6], nums2 = [3,1,7]\n",
    "<b>输出：</b>3\n",
    "<b>解释：</b>数字 3 的数位 3 在两个数组中都出现了。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums1.length, nums2.length &lt;= 9</code></li>\n",
    "\t<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 9</code></li>\n",
    "\t<li>每个数组中，元素 <strong>互不相同</strong>&nbsp;。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [form-smallest-number-from-two-digit-arrays](https://leetcode.cn/problems/form-smallest-number-from-two-digit-arrays/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [form-smallest-number-from-two-digit-arrays](https://leetcode.cn/problems/form-smallest-number-from-two-digit-arrays/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[4,1,3]\\n[5,7]', '[3,5,2,6]\\n[3,1,7]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\tdef maxProfit(self, prices):\n",
    "\t\tif not prices:\n",
    "\t\t\treturn 0\n",
    "\t\tif len(prices)==1:\n",
    "\t\t\t return 0\n",
    "\t\trecords=dict()\n",
    "\t\trecords[-1]=0\n",
    "\t\trecords[0]=0\n",
    "\t\tminNumber=prices[0]\n",
    "\t\tfor i in range(1,len(prices)):\n",
    "\t\t\trecords[i]=max(records[i-1],prices[i]-minNumber)\n",
    "\t\t\tminNumber=min(minNumber,prices[i])\n",
    "\n",
    "\t\treturn records[len(prices)-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        s = set(nums1)&set(nums2)\n",
    "        if s :\n",
    "            return min(s)\n",
    "        n = min(nums1)\n",
    "        m = min(nums2)\n",
    "        return min(n*10+m,m*10+n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        h = [0]*10\n",
    "        for n in nums1: h[n]+=1\n",
    "        for n in nums2: h[n]+=1\n",
    "        for i in range(1,10):\n",
    "            if h[i]==2: return i\n",
    "            \n",
    "        m1, m2 = min(nums1), min(nums2)\n",
    "        return 10*min(m1,m2)+max(m1,m2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        ans = 100\n",
    "        for a in nums1:\n",
    "            for b in nums2:\n",
    "                if a == b:\n",
    "                    ans = min(ans, a)\n",
    "                else:\n",
    "                    ans = min(ans, 10 * a + b, 10 * b + a)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        min_num = 10\n",
    "        for i in nums1:\n",
    "            for j in nums2:\n",
    "                if i == j and i < min_num:\n",
    "                    min_num = i\n",
    "        if min_num < 10:\n",
    "            return min_num\n",
    "        min_num = nums1[0] * 10 + nums2[0]\n",
    "        for i in nums1:\n",
    "            for j in nums2:\n",
    "                if min_num > i * 10 + j:\n",
    "                    min_num = i * 10 + j\n",
    "        for i in nums1:\n",
    "            for j in nums2:\n",
    "                if min_num > i + j * 10:\n",
    "                    min_num = i + j * 10\n",
    "        return min_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        s = set(nums1) & set(nums2) # 取2个集合的交集\n",
    "        if s:\n",
    "            return min(s)\n",
    "        x, y = min(nums1), min(nums2)\n",
    "        return x * 10 + y if x < y else x + y * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        \n",
    "        ans = 100\n",
    "        for a in nums1:\n",
    "            for b in nums2:\n",
    "                if a == b:\n",
    "                    ans = min(ans, a)\n",
    "                else:\n",
    "                    ans = min(ans, 10 * a + b, 10 * b + a)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        jiao=list(set(nums1) & set(nums2))\n",
    "        jiao.sort()\n",
    "        if len(jiao)>=1:\n",
    "            return jiao[0]\n",
    "        return nums1[0]*10+nums2[0] if nums1[0]<nums2[0] else nums2[0]*10+nums1[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1 = set(nums1)  # 将nums1转为集合\n",
    "        nums2 = set(nums2)  # 将nums2转为集合\n",
    "        intersection = nums1 & nums2    # 取两个集合的交集\n",
    "        if intersection:\n",
    "            return min(intersection)    # 如果有在两个数组中都存在的数字，则最小数就是这个数字\n",
    "        min_num1 = min(nums1)   # 记录nums1的最小值\n",
    "        min_num2 = min(nums2)   # 记录nums2的最小值\n",
    "        return 10 * min(min_num1, min_num2) + max(min_num1, min_num2) \n",
    "          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        if not nums1 or not nums2:\n",
    "            return 0\n",
    "        \n",
    "        for i in range(1, 10):\n",
    "            if i in nums1 and i in nums2:\n",
    "                return i\n",
    "        a, b = min(nums1), min(nums2)\n",
    "        if a < b:\n",
    "            return a*10 + b\n",
    "        else:\n",
    "            return b*10 + a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10*nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10*nums2[0] +nums1[0])\n",
    "        else:\n",
    "            return sorted(list(set(nums1) & set(nums2)))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        if inter := (set(nums1) & set(nums2)):\n",
    "            return min(inter)\n",
    "        else:\n",
    "            return min(min(nums1), min(nums2)) * 10 + max(min(nums1), min(nums2))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10*nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10*nums2[0] +nums1[0])\n",
    "        else:\n",
    "            return sorted(list(set(nums1) & set(nums2)))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        intersection = set(nums1) & set(nums2)\n",
    "\n",
    "        intersection_list = list(intersection)\n",
    "        if len(intersection_list) > 0:\n",
    "            return min(intersection_list)\n",
    "        else:\n",
    "            min_a = min(nums1)\n",
    "            min_b = min(nums2)\n",
    "            if min_a < min_b:\n",
    "                return min_a * 10 + min_b\n",
    "            else:\n",
    "                return min_b * 10 + min_a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        ans=99\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                ans=min(ans,i)\n",
    "        return min(ans,10*min(min(nums1),min(nums2))+max((min(nums1),min(nums2))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        a=[]\n",
    "        n=0\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                a.append(i)\n",
    "                n=1\n",
    "        if n==1:\n",
    "            return min(a)\n",
    "        if min(nums1)<min(nums2):\n",
    "            return (min(nums1)*10+min(nums2))\n",
    "        return (min(nums2)*10+min(nums1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        pos = []\n",
    "        for each in nums1:\n",
    "            if each in nums2:\n",
    "                pos.append(each)\n",
    "        \n",
    "        if min(nums1) >= min(nums2):\n",
    "            pos.append(min(nums1)+10*min(nums2))\n",
    "        else:\n",
    "            pos.append(min(nums2)+10*min(nums1))\n",
    "\n",
    "        return min(pos)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        nums = nums1 + nums2\n",
    "        if len(set(nums)) < len(nums1) + len(nums2):\n",
    "            repeat = [num for num in nums if nums.count(num) > 1]\n",
    "            repeat.sort()\n",
    "            return repeat[0]\n",
    "        else:\n",
    "            return nums1[0] * 10 + nums2[0] if nums1[0] < nums2[0] else nums2[0] * 10 + nums1[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        list1 = []\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                list1.append(i)\n",
    "        else:\n",
    "            if not list1:\n",
    "                num1 = min(nums1)\n",
    "                num2 = min(nums2)\n",
    "                if num1<num2:\n",
    "                    return int(str(num1)+str(num2))\n",
    "                else:\n",
    "                    return int(str(num2)+str(num1))\n",
    "        return min(list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if set(nums1).intersection(nums2):\n",
    "            return min(set(nums1).intersection(nums2))\n",
    "        return min(nums1[0],nums2[0]) * 10 + max(nums1[0],nums2[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        s = set(nums1) & set(nums2) # 取交集\n",
    "        if s:\n",
    "            return min(s)\n",
    "        a, b = min(nums1), min(nums2)\n",
    "        return min(a * 10 + b, b * 10 + a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10 * nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10 * nums2[0] + nums1[0])\n",
    "        else:\n",
    "            left,n = 0,len(nums2)\n",
    "            for i in nums1:\n",
    "                while left < n and nums2[left] < i:\n",
    "                    left += 1\n",
    "                if i == nums2[left]:\n",
    "                    return i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "\n",
    "        intersection = set(nums1) & set(nums2)\n",
    "        if intersection:\n",
    "            return min(intersection)\n",
    "\n",
    "        a = min(nums1)\n",
    "        b = min(nums2)\n",
    "\n",
    "        return a*10 + b if a < b else b*10 + a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber1(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        common = []\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                common.append(i)\n",
    "        if len(common) == 0:\n",
    "            n1 = min(nums1)\n",
    "            n2 = min(nums2)\n",
    "            if n1 > n2:\n",
    "                n1, n2 = n2, n1\n",
    "            return n1 * 10 + n2\n",
    "        else:\n",
    "            return min(common)\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        arr1, arr2 = nums1, nums2\n",
    "        min1 = 10\n",
    "        for i in arr1:\n",
    "            if i in arr2 and min1>i:\n",
    "                min1 = i\n",
    "        if min1 !=10:\n",
    "            return min1\n",
    "        for i in arr1:\n",
    "            if min1>i:\n",
    "                min1= i\n",
    "        min2 = 10\n",
    "        for i in arr2:\n",
    "            if min2>i:\n",
    "                min2 = i\n",
    "        return min(min1*10 + min2,min2*10 + min1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        xxx=999\n",
    "        for x in nums1:\n",
    "            for y in nums2:\n",
    "                if x==y:\n",
    "                    xxx=min(xxx,x)\n",
    "        a,b=min(nums1),min(nums2)\n",
    "        return min(xxx,min(a*10+b,b*10+a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        lst=list()\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                lst.append(i)\n",
    "        a=min(nums1)\n",
    "        b=min(nums2)\n",
    "        if a>b:\n",
    "            a,b=b,a\n",
    "        c=a*10+b\n",
    "        lst.append(c)\n",
    "        return min(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        num = set(nums1) & set(nums2)\n",
    "        if num:\n",
    "            return min(num)\n",
    "        else:\n",
    "\n",
    "            return int(\"\".join(sorted([str(min(nums1)), str(min(nums2))])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        m = set(nums1).intersection(nums2)\n",
    "        if m:\n",
    "            return min(m)\n",
    "        n = min(nums1), min(nums2)\n",
    "        return min(n) * 10 + max(n)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        if set(nums1)&set(nums2):\n",
    "            return min(set(nums1)&set(nums2))\n",
    "        return min(nums1)*10+min(nums2) if min(nums1)<min(nums2) else min(nums2)*10+min(nums1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10*nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10*nums2[0] +nums1[0])\n",
    "        else:\n",
    "            for i in nums1:\n",
    "                if i in nums2:\n",
    "                    return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        for num in nums1:\n",
    "            if num in nums2:\n",
    "                return num\n",
    "        return 10 * min(nums1[0],nums2[0]) + max(nums1[0],nums2[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10 * nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10 * nums2[0] + nums1[0])\n",
    "        else:\n",
    "            for i in nums1:\n",
    "                if i in nums2:\n",
    "                    return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10 * nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10 * nums2[0] + nums1[0])\n",
    "        else:\n",
    "            left,n = 0,len(nums2)\n",
    "            for i in nums1:\n",
    "                while left < n and nums2[left] < i:\n",
    "                    left += 1\n",
    "                if i == nums2[left]:\n",
    "                    return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        \n",
    "        ans = inf\n",
    "        for num1 in nums1:\n",
    "            if num1 in nums2:\n",
    "                ans = min(ans, num1)\n",
    "            for num2 in nums2:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "        \n",
    "        for num1 in nums2:\n",
    "            for num2 in nums1:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "                \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        \n",
    "        ans = inf\n",
    "        for num1 in nums1:\n",
    "            for num2 in nums2:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "        \n",
    "        \n",
    "        for num1 in nums2:\n",
    "            for num2 in nums1:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "                \n",
    "        for num in nums1:\n",
    "            if num in nums2:\n",
    "                ans = min(ans,num)\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                return i\n",
    "        nums2.sort()\n",
    "        if nums1[0] < nums2[0]:\n",
    "            return 10*nums1[0]+nums2[0]\n",
    "        else:\n",
    "            return 10*nums2[0]+nums1[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        n1=sorted(nums1)\n",
    "        n2=sorted(nums2)\n",
    "        for i in n1:\n",
    "            for j in n2:\n",
    "                if j==i:\n",
    "                    return j\n",
    "        s=min(n1[0],n2[0])\n",
    "        g=max(n1[0],n2[0])\n",
    "        return s*10+g\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1=sorted(list(nums1),reverse=False)\n",
    "        nums2=sorted(list(nums2),reverse=False)\n",
    "        for i in range(len(nums1)):\n",
    "            for j in range(len(nums2)):\n",
    "                if nums1[i] == nums2[j]:\n",
    "                    return nums1[i]\n",
    "        if nums1[0] < nums2[0]:\n",
    "            return nums1[0]*10+nums2[0]\n",
    "        elif nums1[0] > nums2[0]:\n",
    "            return nums2[0]*10+nums1[0]\n",
    "        else:\n",
    "            return nums2[0]     \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        \n",
    "        ans = inf\n",
    "        for num1 in nums1:\n",
    "            for num2 in nums2:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "        \n",
    "        for num1 in nums2:\n",
    "            for num2 in nums1:\n",
    "                ans = min(ans, num2 + 10 * num1)\n",
    "        \n",
    "        for num in nums1:\n",
    "            if num in nums2:\n",
    "                ans = min(ans,num)\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        min1 = min(nums1)\n",
    "        min2 = min(nums2)\n",
    "        ans = min(min1 * 10 + min2, min2 * 10 + min1)\n",
    "\n",
    "        tmp = sorted(Counter(nums1 + nums2).items(), key=lambda x: (-x[1], x[0]))\n",
    "        key, val = tmp[0][0], tmp[0][1]\n",
    "        if val > 1 and key < ans:\n",
    "            return key\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        record=[0]*10\n",
    "        min_1,min_2,min_all=9,9,10\n",
    "        for i in nums1:\n",
    "            if min_1>i:\n",
    "                min_1=i\n",
    "            record[i]=1\n",
    "        for i in nums2:\n",
    "            if record[i]==1 and min_all>i:\n",
    "                min_all=i\n",
    "            if min_2>i:\n",
    "                min_2=i\n",
    "        if min_all<10:\n",
    "            return min_all\n",
    "        if min_1<min_2:\n",
    "            return min_1*10+min_2\n",
    "        return min_2*10+min_1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        if set(nums1) & set(nums2):\n",
    "            return min(set(nums1) & set(nums2))\n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        res = min(x*10+y, x+10*y)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        \n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        \n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        mask1 = mask2 = 0\n",
    "        for x in nums1:\n",
    "            mask1 |= 1 << x\n",
    "        for x in nums2:\n",
    "            mask2 |= 1 << x\n",
    "        mask = mask1 & mask2\n",
    "        if mask:\n",
    "            return (mask & -mask).bit_length() - 1\n",
    "        a = (mask1 & -mask1).bit_length() - 1\n",
    "        b = (mask2 & -mask2).bit_length() - 1\n",
    "        return min(a * 10 + b, b * 10 + a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1=sorted(list(nums1),reverse=False)\n",
    "        nums2=sorted(list(nums2),reverse=False)\n",
    "        for i in range(len(nums1)):\n",
    "            for j in range(len(nums2)):\n",
    "                if nums1[i] == nums2[j]:\n",
    "                    return nums1[i]\n",
    "        if nums1[0] < nums2[0]:\n",
    "            return nums1[0]*10+nums2[0]\n",
    "        elif nums1[0] > nums2[0]:\n",
    "            return nums2[0]*10+nums1[0]\n",
    "        else:\n",
    "            return nums2[0]     \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        for i,val in enumerate(nums1):\n",
    "            if val in nums2:\n",
    "                return val\n",
    "        a=str(min(nums1))\n",
    "        b=str(min(nums2))\n",
    "        return int(a+b) if a+b<b+a else int(b+a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        \n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                return i\n",
    "        if nums1[0] > nums2[0]:\n",
    "            return int(str(nums2[0]) + str(nums1[0]))\n",
    "        else:\n",
    "            return int(str(nums1[0]) + str(nums2[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)\n",
    "            return -1 if not s else min(s)\n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return x*10+y if x<y else y*10+x\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums = list(set(nums1)&set(nums2))\n",
    "        if len(nums)>0:\n",
    "            return min(nums)\n",
    "        num1 = str(min(nums1))\n",
    "        num2 = str(min(nums2))\n",
    "        return int(''.join(num1+num2)) if num1<num2 else int(''.join(num2+num1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        ans = 100\n",
    "        for a in nums1:\n",
    "            for b in nums2:\n",
    "                if a == b:\n",
    "                    ans = min(ans, a)\n",
    "                else:\n",
    "                    ans = min(ans, 10 * a + b, 10 * b + a)\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        if not (set(nums1) & set(nums2)):\n",
    "            return (10 * nums1[0] + nums2[0]) if (nums1[0] <= nums2[0]) else (10 * nums2[0] + nums1[0])\n",
    "        else:\n",
    "            left,n = 0,len(nums2)\n",
    "            for i in nums1:\n",
    "                while left < n and nums2[left] < i:\n",
    "                    left += 1\n",
    "                if i == nums2[left]:\n",
    "                    return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        for num in nums1:\n",
    "            if num in nums2:\n",
    "                return num\n",
    "\n",
    "        return min(nums1[0], nums2[0]) * 10 + max(nums1[0], nums2[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        nums1.sort()\n",
    "        nums2.sort()\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                return i\n",
    "        return min(nums1[0]*10+nums2[0], nums2[0]*10+nums1[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        def same() -> int:\n",
    "            s = set(nums1) & set(nums2)  # 求两个集合的交集\n",
    "            return -1 if not s else min(s)\n",
    "\n",
    "        if (x := same()) != -1:\n",
    "            return x\n",
    "\n",
    "        # 只是需要最小值的情况下，不需要排序，降低时间复杂度\n",
    "        x = min(nums1)\n",
    "        y = min(nums2)\n",
    "        return min(x * 10 + y, y * 10 + x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        record=[0]*10\n",
    "        min_1,min_2,min_all=9,9,10\n",
    "        for i in nums1:\n",
    "            if min_1>i:\n",
    "                min_1=i\n",
    "            record[i]=1\n",
    "        for i in nums2:\n",
    "            if record[i]==1 and min_all>i:\n",
    "                min_all=i\n",
    "            if min_2>i:\n",
    "                min_2=i\n",
    "        if min_all<10:\n",
    "            return min_all\n",
    "        if min_1<min_2:\n",
    "            return min_1*10+min_2\n",
    "        return min_2*10+min_1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        min1,min2 = min(nums1),min(nums2)\n",
    "        res = 99\n",
    "        for num in nums1:\n",
    "            if num in nums2:\n",
    "                res = min(res,num)\n",
    "        return min([res,min1*10+min2,min2*10+min1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        ans = 100\n",
    "        for a in nums1:\n",
    "            for b in nums2:\n",
    "                if a == b:\n",
    "                    ans = min(ans, a)\n",
    "                else:\n",
    "                    ans = min(ans, 10 * a + b, 10 * b + a)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        m = 100\n",
    "        for i in nums1:\n",
    "            if i in nums2:\n",
    "                m = min(m, i)\n",
    "        return min(m, int(str(min(nums1)) + str(min(nums2))),int(str(min(nums2)) + str(min(nums1))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        a = 10\n",
    "        for x in nums1:\n",
    "            if x in nums2:\n",
    "                a = min(x, a)\n",
    "        if a != 10 :\n",
    "            return a\n",
    "        if (min(nums1) == min(nums2)):\n",
    "            return min(nums1)\n",
    "        elif(min(nums1) > min(nums2)):\n",
    "            return min(nums2) * 10 + min(nums1)\n",
    "        else:\n",
    "            return min(nums1) * 10 + min(nums2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        joint = [num for num in nums1 if num in nums2]\n",
    "        if len(joint) != 0:\n",
    "            return min(joint)\n",
    "        min1, min2 = min(nums1), min(nums2)\n",
    "        if min1 < min2:\n",
    "            return min1*10+min2\n",
    "        else:\n",
    "            return min2*10+min1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        for i in range(1, 10):\n",
    "            if i in nums1 and i in nums2:\n",
    "                return i\n",
    "\n",
    "        n1, n2 = min(nums1), min(nums2)\n",
    "        return min(n1*10+n2, n2*10+n1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        tmp=set(nums1)&set(nums2)\n",
    "        if tmp:\n",
    "            return min(tmp)\n",
    "        m1,m2=min(nums1),min(nums2)\n",
    "        return m2*10+m1 if m1>m2 else m1*10+m2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        \n",
    "        cnt = Counter(nums1 + nums2)\n",
    "        res = 100\n",
    "        earlystop = False\n",
    "        for k, v in cnt.items():\n",
    "            \n",
    "            if v > 1:\n",
    "                res = min(res, k)\n",
    "                earlystop = True\n",
    "        if earlystop: return res\n",
    "\n",
    "        a, b = min(nums1), min(nums2)\n",
    "\n",
    "        return min(a,b) * 10 + max(a, b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        record=[0]*10\n",
    "        min_1,min_2,min_all=9,9,10\n",
    "        for i in nums1:\n",
    "            if min_1>i:\n",
    "                min_1=i\n",
    "            record[i]=1\n",
    "        for i in nums2:\n",
    "            if record[i]==1 and min_all>i:\n",
    "                min_all=i\n",
    "            if min_2>i:\n",
    "                min_2=i\n",
    "        if min_all<10:\n",
    "            return min_all\n",
    "        if min_1<min_2:\n",
    "            return min_1*10+min_2\n",
    "        return min_2*10+min_1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        q=100\n",
    "        for a in nums1:\n",
    "            for b in nums2:\n",
    "                if a==b:\n",
    "                    q=min(q,a) \n",
    "                else:    \n",
    "                    q=min(q,a*10+b,b*10+a)\n",
    "        return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import heapq\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        #一个数\n",
    "        st1=set(nums1)\n",
    "        heap=[]\n",
    "        for i in nums2:\n",
    "            if i in st1:\n",
    "                heapq.heappush(heap,i)\n",
    "        if len(heap)!=0:\n",
    "            return heap[0]\n",
    "        a,b=min(nums1),min(nums2)\n",
    "        return min(int(str(a)+str(b)),int(str(b)+str(a)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        hash = [0] * 10\n",
    "        for x in nums1:\n",
    "            hash[x] += 1\n",
    "        for x in nums2:\n",
    "            hash[x] += 2\n",
    "        n1, n2 = 10, 10\n",
    "        for i in range(1, 10):\n",
    "            if hash[i] == 3:\n",
    "                return i\n",
    "            if hash[i] == 1:\n",
    "                n1 = min(n1, i)\n",
    "            if hash[i] == 2:\n",
    "                n2 = min(n2, i)\n",
    "        return n2*10+n1 if n1>=n2 else n1*10+n2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        min1=min(nums1)\n",
    "        min2=min(nums2)\n",
    "        nums1=set(nums1)\n",
    "        nums2.sort()\n",
    "        for i in nums2:\n",
    "            if i in nums1:return i\n",
    "        return min(min1*10+min2,min2*10+min1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minNumber(self, nums1: List[int], nums2: List[int]) -> int:\n",
    "        ans, min1, min2 = 10, 10, 10\n",
    "        nums = []\n",
    "        for item in nums1:\n",
    "            min1 = min(min1, item)\n",
    "            nums.append(item)\n",
    "        for item in nums2:\n",
    "            min2 = min(min2, item)\n",
    "            if item in nums:\n",
    "                ans = min(ans, item)\n",
    "        if ans != 10: return ans\n",
    "        elif min1 < min2: return min1 * 10 + min2\n",
    "        else: return min2 * 10 + min1\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
